

package hibernate;



import java.util.logging.Level;
import org.hibernate.*;
import org.hibernate.cfg.*;

public class HibernateUtil {
    private static SessionFactory sessionFactory;
    private static Session session;
    public static void inicializar() {
        try {
        java.util.logging.Logger.getLogger("org.hibernate.cfg").setLevel(Level.SEVERE);
            //sessionFactory = new AnnotationConfiguration().buildSessionFactory();
            AnnotationConfiguration conf = new AnnotationConfiguration();
                
                conf.setProperty("hibernate.connection.driver_class","org.postgresql.Driver");
                conf.setProperty("hibernate.dialect","org.hibernate.dialect.PostgreSQLDialect");  
                conf.setProperty("hibernate.connection.url","jdbc:postgresql://localhost:5432/salud_familiar");

                conf.setProperty("hibernate.connection.username","postgres");
                conf.setProperty("hibernate.connection.password","raul5745");

                conf.setProperty("hibernate.connection.pool_size","10");                
                conf.setProperty("show_sql","true");
//                conf.setProperty("hibernate.hbm2ddl.auto","update");
                           
                
                conf.addPackage("modelo.personas");
                conf.addAnnotatedClass(modelo.personas.Persona.class);
                conf.addAnnotatedClass(modelo.personas.PersonaFisica.class);
                conf.addAnnotatedClass(modelo.personas.Telefono.class);
                conf.addAnnotatedClass(modelo.personas.Documento.class);
                conf.addAnnotatedClass(modelo.personas.Domicilio.class);
                
                conf.addPackage("modelo.personas.pacientes");
                conf.addAnnotatedClass(modelo.personas.pacientes.HistoriaClinica.class);
                conf.addAnnotatedClass(modelo.personas.pacientes.Parentesco.class);
                conf.addAnnotatedClass(modelo.personas.pacientes.Pariente.class);
                conf.addAnnotatedClass(modelo.personas.pacientes.Paciente.class);
                conf.addAnnotatedClass(modelo.personas.pacientes.DetalleHistoriaClinica.class);
                
                conf.addPackage("modelo.personas.profesionales");
                conf.addAnnotatedClass(modelo.personas.profesionales.Especialidad.class);
                conf.addAnnotatedClass(modelo.personas.profesionales.Profesional.class);
                
                conf.addPackage("modelo.patologias");
                conf.addAnnotatedClass(modelo.patologias.TipoEnfermedad.class);
                conf.addAnnotatedClass(modelo.patologias.Enfermedad.class);
                conf.addAnnotatedClass(modelo.patologias.Sintoma.class);
                
                conf.addPackage("geografia");
                conf.addAnnotatedClass(geografia.Localidad.class);
                conf.addAnnotatedClass(geografia.Provincia.class);
                
                   
            sessionFactory = conf.buildSessionFactory();
            session=sessionFactory.openSession();

        } catch (Throwable ex) {
// Log exception!
            throw new ExceptionInInitializerError(ex);
        }
    }
    
    public static Session getSession()
    throws HibernateException {
        return session;
    }
}